<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 查找数据在数组中最先出现的下标
    var arr = [1,2,3,4,"5","6","xx"]
    console.log(arr.indexOf("4"));//-1
    console.log(arr.indexOf(4));//3
    console.log(arr.indexOf(4,3));//3
    console.log(arr.indexOf(4,-2));//-1 负数倒数起始位置，然后正向查找
    console.log(arr.indexOf("5",-5));//4
    // 查找数据在数组中最后一次出现的下标
    var arr1 = [1,12,3,14,"5","6","xx",14,14,"5","6","xx"]
    console.log(arr1.lastIndexOf(5));//-1
    console.log(arr1.lastIndexOf("xx",8));//6
    console.log(arr1.lastIndexOf(14,-5));//7
    // 翻转数组
    arr.reverse()
    console.log(arr);


    // sort()默认根据字符编码顺序，从小到大排序
    var arr2 = [1,12,3,14,"5","6","xx",14,14,"5","6","xx",11100,"sads","a1","1a","是","好"]
    console.log(arr2);
    console.log(arr2.sort());
    arr2.sort(function (a,b) {
      return a-b;
    })
    console.log(arr2);

    // join() 通过参数作为连字符将数组中的每一项用连字符连成一个完整的字符串
    var arr3 = [1,12,3,14,"5","6","xx"]
    console.log(arr3);
    console.log(arr3.join());//1,12,3,14,5,6,xx
    console.log(arr3.join(""));//11231456xx
    console.log(arr3.join("22"));//12212223221422522622xx


    // 清空数组
    // 方式1 推荐
    arr = [];
    // 方式2
    arr.length = 0;
    // 方式3
    arr.splice(0, arr.length);

    // 字符串对象
      // 字符串是不可变的(字符串所有的方法，都不会修改字符串本身，操作完成会返回一个新的字符串。)
    // 长度属性： str.length

    // // 冒泡排序
    // var arr4 =[1,12,3,14,"5","6","xx",14,14,"5","6","xx",11100,"sads","a1","1a","是","好"]
    // console.log(arr4.length);
    // function fun(arr4){
    //   for (var i = 0; i < arr4.length - 1; i++) {
    //     for (var j = 0; j < arr4.length - 1 - i; j++) {
    //       if (arr4[j]>arr4[j+1]) {
    //         var cd = arr4[j+1];
    //         arr4[j+1] =arr4[j];
    //         arr4[j] = cd; 
    //       }
    //     }

    //   }
    //   return arr4;
    // }
    // fun(arr4)
    // console.log(arr4);

    // 函数内部引用变量也是引用的地址，也会同时改变
    var arr5 =[1,12,3,14,"5","6","xx",14,14,"5","6","xx",11100,"sads","a1","1a","是","好"]
    function cun() {
      var arr6 =arr5;
      arr6[3] = 22222222222;
      console.log(arr6)//[1, 12, 3, 22222222222, '5', '6', 'xx', 14, 14, '5', '6', 'xx', 11100, 'sads', 'a1', '1a', '是', '好']
    }
    console.log(arr5);//(18) [1, 12, 3, 22222222222, '5', '6', 'xx', 14, 14, '5', '6', 'xx', 11100, 'sads', 'a1', '1a', '是', '好']
    cun()
    // console.log(arr6);

    // JavaScript包含ECMAscript和DOM\BOM
    // EMACscript中包含变量，数组，函数，对象，循环语句，条件分支语句，数据，运算符
    // JavaScript包含浏览器对象，自定义对象，内置对象
    // ECMAscript浏览器对象，自定义对象
  </script>
</body>
</html>